# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=yazi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=25.4.8
pkgrel=1
pkgdesc="Blazing fast terminal file manager written in Rust, based on async I/O (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://yazi-rs.github.io'
msys2_repository_url='https://github.com/sxyazi/yazi'
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" 'git')
optdepends=("${MINGW_PACKAGE_PREFIX}-jq: for JSON preview"
            "${MINGW_PACKAGE_PREFIX}-fd: for file search"
            "${MINGW_PACKAGE_PREFIX}-ripgrep: for file contents search"
            "${MINGW_PACKAGE_PREFIX}-fzf: for directory jumping"
            "${MINGW_PACKAGE_PREFIX}-poppler: for PDF preview"
            "${MINGW_PACKAGE_PREFIX}-zoxide: for directory jumping"
            "${MINGW_PACKAGE_PREFIX}-ttf-nerd-fonts-symbols: for file icons")
source=("git+${msys2_repository_url}.git#tag=v${pkgver}")
sha256sums=('46953adf9986f37892be65efabc6696712d14da466ce4046df9c6e284fc5e92e')

_env() {
  export YAZI_GEN_COMPLETIONS=1
  export WINAPI_NO_BUNDLED_LIBRARIES=1
}

prepare() {
  cd "${_realname}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}"

  _env
  cargo build --profile release-windows --frozen -p yazi-fm -p yazi-cli
}

check() {
  cd "${_realname}"

  _env
  cargo test --profile release-windows --frozen -p yazi-fm -p yazi-cli
}

package() {
  cd "${_realname}"

  install -Dm755 target/release-windows/ya{,zi}.exe -t "${pkgdir}${MINGW_PREFIX}/bin"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  (cd "yazi-boot/completions"
  install -Dm644 "yazi.bash" "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/yazi"
  install -Dm644 "yazi.fish" "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/yazi.fish"
  install -Dm644 "_yazi" "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_yazi")

  (cd "yazi-cli/completions"
  install -Dm644 "ya.bash" "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/ya"
  install -Dm644 "ya.fish" "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/ya.fish"
  install -Dm644 "_ya" "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_ya")
}
